package com.test.socket;

import   java.net.*;   
import   java.io.IOException;   
  
public   class   UDPrecv   {   
  
public   static   void   main(String[]   args)   {   
  
	while(true)   
	{   
		try   {   
		DatagramSocket   ds   =   new   DatagramSocket(3000);   
		  
		byte[]   buf   =   new   byte[1024];   
		DatagramPacket   dp   =   new   DatagramPacket(buf,buf.length);   
		  
		ds.receive(dp);   
		String   msg   =   new   String(dp.getData(),0,dp.getLength());   
		System.out.println(   msg   +   "   From   :"+dp.getAddress().getHostAddress()   +   "   Port   :"+   
							dp.getPort()   );   
		ds.close();   
	  
			if   (msg.equals("bye"))   
			break;   
		}catch(SocketException   sException){   
	  
			System.out.println("the   socket   could   not   be   opened   ");   
		}catch(IOException   ioE){   
	  
		System.out.println("I/O   error   occurs   ");   
		}   
		}   
	}   
}   

